package world.hezi.utils;

import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.data.At;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import net.mamoe.mirai.message.data.QuoteReply;

/**
 * @author wangzijian
 * @date 2022/10/19 16:57
 */
public class CommonUtil {
    public static String getException(Exception e){
        StringBuilder stringBuilder = new StringBuilder(e +"\n");
        for (StackTraceElement stackTraceElement : e.getStackTrace()) {
            stringBuilder.append("\tat ").append(stackTraceElement).append("\n");
        }
        for (Throwable throwable : e.getSuppressed()) {
            stringBuilder.append("\tat ").append(throwable).append("\n");
        }
        if(e.getCause()!=null)
            stringBuilder.append("\t").append(e.getCause());
        return stringBuilder.toString();
    }
    public static void sendQuoteReplyMessage(MessageEvent event, String message){
        MessageChain chain = new MessageChainBuilder()
                .append(new QuoteReply(event.getMessage()))
                .append(new At(event.getSender().getId()))
                .append("\n").append(message)
                .build();
        event.getSubject().sendMessage(chain);
    }
}
